Technical Q&As
IC 04 - Deselecting Icons in the Finder (11-July-97)
Q
Is there any way to programmatically deselect icons that were
previously selected in the Finder?
A
Yes, actually, there are a few different methods you can use. You
can deselect all icons that are selected in the Finder by doing the
following:
- You can do this through AppleScript by doing the following:
ignoring application responses
tell application "Finder" to set selection to {}
end ignoring
This is equivalent to sending the event with
kAENoReply
.
- If you want to do this from within your application and don't want to
go through the trouble of building up the proper AppleEvents to send to
the Finder, you can pre-compile the above script and use
OSALoadExecute
()
to invoke it. You can pre-compile the script and use OSALoadExecute
()
to invoke it. This is covered in
Inside Macintosh - Interapplication Communication pg 10-61 thru 10-63.
These two methods will deslect ALL icons that are selected in the Finder.
On the other hand, if you only want to deselect the icon for a particular
item, you would need to ask the Finder for the selection, walk through
the list of selected items, remove your item, then set the selection to
the resulting list.
Check out the develop issue 20 article "Scripting the Finder From Your Application"
for details on getting and setting the Finder selection.
An alternate way of performing the action would be to build an Apple
event procedurally and send the event by calling AESend
.
-- Lenae Rowland
Worldwide Developer Technical Support
Technical Q&As
Previous Question | Contents
To contact us, please use the Contact Us page.